<template>
  <view class="loading-spinner" v-if="visible">
    <view class="spinner-overlay" v-if="overlay"></view>
    <view class="spinner-container">
      <view class="spinner" :class="{ [`spinner-${size}`]: true }">
        <view class="spinner-dot" v-for="n in 12" :key="n"></view>
      </view>
      <text class="spinner-text" v-if="text">{{ text }}</text>
    </view>
  </view>
</template>

<script setup lang="ts">
interface Props {
  visible?: boolean
  text?: string
  size?: 'small' | 'medium' | 'large'
  overlay?: boolean
}

withDefaults(defineProps<Props>(), {
  visible: true,
  size: 'medium',
  overlay: true
})
</script>

<style lang="scss" scoped>
.loading-spinner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  
  .spinner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
  }
  
  .spinner-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    backdrop-filter: blur(10px);
  }
  
  .spinner {
    position: relative;
    
    &.spinner-small {
      width: 20px;
      height: 20px;
    }
    
    &.spinner-medium {
      width: 30px;
      height: 30px;
    }
    
    &.spinner-large {
      width: 40px;
      height: 40px;
    }
    
    .spinner-dot {
      position: absolute;
      width: 8%;
      height: 20%;
      background: #409EFF;
      border-radius: 50px;
      animation: spinner-fade 1.2s linear infinite;
      
      &:nth-child(1) { transform: rotate(0deg) translate(0, -150%); animation-delay: 0s; }
      &:nth-child(2) { transform: rotate(30deg) translate(0, -150%); animation-delay: 0.1s; }
      &:nth-child(3) { transform: rotate(60deg) translate(0, -150%); animation-delay: 0.2s; }
      &:nth-child(4) { transform: rotate(90deg) translate(0, -150%); animation-delay: 0.3s; }
      &:nth-child(5) { transform: rotate(120deg) translate(0, -150%); animation-delay: 0.4s; }
      &:nth-child(6) { transform: rotate(150deg) translate(0, -150%); animation-delay: 0.5s; }
      &:nth-child(7) { transform: rotate(180deg) translate(0, -150%); animation-delay: 0.6s; }
      &:nth-child(8) { transform: rotate(210deg) translate(0, -150%); animation-delay: 0.7s; }
      &:nth-child(9) { transform: rotate(240deg) translate(0, -150%); animation-delay: 0.8s; }
      &:nth-child(10) { transform: rotate(270deg) translate(0, -150%); animation-delay: 0.9s; }
      &:nth-child(11) { transform: rotate(300deg) translate(0, -150%); animation-delay: 1.0s; }
      &:nth-child(12) { transform: rotate(330deg) translate(0, -150%); animation-delay: 1.1s; }
    }
  }
  
  .spinner-text {
    margin-top: 12px;
    font-size: 14px;
    color: #606266;
  }
}

@keyframes spinner-fade {
  0%, 39%, 100% {
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
}
</style>
